package com.csaba.swing.action;

import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.Action;

import com.csaba.util.LoggerHelper;

public class ActionFactory
{
	private final static Logger logger = LoggerHelper.getDefaultLogger();

	private static HashMap<Class<?>, Action> actions = new HashMap<Class<?>, Action>();

	public static Action getAction( final Class<?> actionClass )
	{
		if ( !actions.containsKey(actionClass) )
			try
			{
				actions.put(actionClass, (Action) actionClass.newInstance());
			}
			catch ( final Exception ex )
			{
				logger.log(Level.SEVERE, "Invalid action class!", ex); //$NON-NLS-1$
				return null;
			}

		return actions.get(actionClass);
	}
}
